﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Subjects.aspx.cs" Inherits="Web.Subjects" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">

    <link rel="stylesheet" href="Share/Styles/Subjects.css" />

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Main" runat="server">

    <asp:UpdatePanel ID="UpdatePanelSubjects" runat="server">
        <ContentTemplate>

            <section class="inset-shadow box w250 left">

                <header>
                    <h3>Предметы</h3>

                    <% if (PermissionService.CanCUDSubjects())
                       { %>
                    <div class="right-top cud-links">
                        <asp:LinkButton runat="server" ID="BtnAddSubject" OnClick="BtnAddSubject_OnClick" Text="Добавить" ToolTip="Добавить предмет" />
                    </div>
                    <% } %>
                </header>

                <% if (PermissionService.CanCUDSubjects())
                   { %>
                <aside runat="server" id="EditSubjectForm" visible="False" class="form">

                    <div runat="server" id="EditSubjectFormError" class="form-error" />

                    <table>
                        <tr>
                            <td>
                                <asp:Label runat="server" AssociatedControlID="TbSubjectName" Text="Название" />
                            </td>
                            <td>
                                <asp:TextBox runat="server" ID="TbSubjectName" TextMode="SingleLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Label runat="server" AssociatedControlID="TbSubjectShortName" Text="Короткое название" />
                            </td>
                            <td>
                                <asp:TextBox runat="server" ID="TbSubjectShortName" TextMode="SingleLine"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <asp:Button runat="server" ID="BtnSaveSubject" Text="Сохранить" CssClass="button" OnClick="BtnSaveSubject_OnClick" />
                                <asp:Button runat="server" ID="ButtonDeleteSubject" Text="Удалить" CssClass="button" OnClientClick="return confirm('Точно удалить?');" OnClick="ButtonDeleteSubject_OnClick" />
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <asp:Button runat="server" ID="BtnCancel" CssClass="button" Text="Отменить" ToolTip="Отменить" OnClick="BtnCancel_OnClick" />
                            </td>
                        </tr>
                    </table>
                </aside>
                <% } %>

                <asp:ListView runat="server" ID="SubjectsList" DataKeyNames="Id" OnItemDataBound="SubjectsList_OnItemDataBound">

                    <LayoutTemplate>
                        <asp:PlaceHolder runat="server" ID="ItemPlaceholder"></asp:PlaceHolder>
                    </LayoutTemplate>

                    <ItemTemplate>
                        <article class="border-top-silver clear-fix">

                            <header>

                                <asp:Label ID="LblSubjectShortName" runat="server" Text='<%# Eval("ShortName") %>' />
                                <h5>
                                    <asp:HyperLink runat="server" NavigateUrl='<%# string.Format("/Subjects.aspx?SubjectId={0}",Eval("Id")) %>' Text='<%# Eval("Name") %>'></asp:HyperLink>
                                </h5>

                                <% if (PermissionService.CanCUDSubjects())
                                   { %>
                                <div class="right-top cud-links">
                                    <asp:LinkButton runat="server" ID="BtnChangeSubject" Text="Изменить" ToolTip="Изменить предмет" OnClick="BtnChangeSubject_OnClick" />
                                </div>
                                <% } %>
                            </header>

                            <div class="left">
                                <p>
                                    Ведут предмет:
                                    <br />
                                    <asp:ListView runat="server" ID="TeachersList" DataKeyNames="Id">

                                        <LayoutTemplate>
                                            <asp:PlaceHolder runat="server" ID="ItemPlaceholder"></asp:PlaceHolder>
                                        </LayoutTemplate>

                                        <ItemTemplate>
                                            <asp:HyperLink runat="server" NavigateUrl="#" ToolTip='<%# Eval("Fio") %>' Text='<%# string.Format("{0} ({1})", Eval("Fio"), Eval("Login")) %>' />
                                            <br />
                                        </ItemTemplate>

                                        <EmptyDataTemplate>
                                            Пока что ни один преподаватель не преподает этот предмет.
                                        </EmptyDataTemplate>

                                    </asp:ListView>
                            </div>

                        </article>
                    </ItemTemplate>

                    <EmptyDataTemplate>
                        Пока что не добавлено ни одного предмета.
                    </EmptyDataTemplate>

                </asp:ListView>


            </section>

        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="BtnSaveSubject" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="BtnAddSubject" EventName="Click" />
        </Triggers>

    </asp:UpdatePanel>

</asp:Content>
